//    Copyright (c) 2009 Elwyn Malethan
//
//    This file is part of SeemoreJ.
//
//    SeemoreJ is free software: you can redistribute it and/or modify
//    it under the terms of the GNU General Public License as published by
//    the Free Software Foundation, either version 3 of the License, or
//    (at your option) any later version.
//
//    SeemoreJ is distributed in the hope that it will be useful,
//    but WITHOUT ANY WARRANTY; without even the implied warranty of
//    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
//    GNU General Public License for more details.

//    You should have received a copy of the GNU General Public License
//    along with SeemoreJ.  If not, see <http://www.gnu.org/licenses/>.

package com.malethan.seemorej.taglib;

import com.malethan.seemorej.taglib.elements.Checkbox;
import com.malethan.seemorej.taglib.elements.Hiddenfield;

public class CheckboxTag extends ElementTag {
    //----------------------------------------------------------------------- Static Properties and Constants
    //----------------------------------------------------------------------- Static Methods
    //----------------------------------------------------------------------- Instance Properties

    String checked;
    String checkedValue = "true";
    String unCheckedValue = "false";

    //----------------------------------------------------------------------- Constructors
    //----------------------------------------------------------------------- Getters and Setters

    public void setChecked(String checked) {
        this.checked = checked;
    }

    public void setCheckedValue(String checkedValue) {
        this.checkedValue = checkedValue;
    }

    public void setUnCheckedValue(String unCheckedValue) {
        this.unCheckedValue = unCheckedValue;
    }

    //----------------------------------------------------------------------- Instance Methods

    protected String constructElement() {
        Checkbox check = new Checkbox();

        setCommonAttributes(check);

        //Overrride value since a checkbox is a special case
        check.setValue(checkedValue);

        if (checkedValue.equals(String.valueOf(value))) {
            check.setChecked("checked");
        }

        Hiddenfield hidden = new Hiddenfield();
        setCommonAttributes(hidden);

        //Overrride value since a checkbox is a special case
        hidden.setValue(unCheckedValue);
        

        return check.toString() + " " + hidden.toString();
    }
}
